package com.weixin.paleituo.factory;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.weixin.paleituo.bean.ClassifyBean;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.fragment.ClassifyBrandFragment;
import com.weixin.paleituo.util.LogUtils;

import java.util.HashMap;

/**
 * Author yichao
 * Time  2017/11/30 9:36
 * Dest  商品分类fragment的工厂
 */

public class ClassGoodsFragmentFactory {
    public static String TAG="ClassGoodsFragmentFactory";
    private static final int FURNITURE_FRAGMENT = 0;
    private static final int HOME_DECORATION_FRAGMENT = 1;
    private static final int HOME_APPLIANCES_FRAGMENT = 2;
    private static HashMap<Integer,Fragment> mMap=new HashMap();
    private static Bundle sBundle;


    public static Fragment getFragment(int index, ClassifyBean classifyBean) {
        Fragment fragment=null;
        if (mMap.containsKey(index)){
            fragment=   mMap.get(index);
            LogUtils.i(TAG,"复用"+index);
            sBundle = new Bundle();
            switch (index){
                case FURNITURE_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,classifyBean);
                    fragment.setArguments(sBundle);
                    break;
                case HOME_DECORATION_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,classifyBean);
                    fragment.setArguments(sBundle);
                    break;
                case HOME_APPLIANCES_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,classifyBean);
                    fragment.setArguments(sBundle);
                    break;
            }

        }else {
            switch (index) {
                case FURNITURE_FRAGMENT:
                    fragment =  ClassifyBrandFragment.getInstance(classifyBean);
                    break;
                case HOME_DECORATION_FRAGMENT:
                    fragment =  ClassifyBrandFragment.getInstance(classifyBean);
                    break;
                case HOME_APPLIANCES_FRAGMENT:
                    fragment =  ClassifyBrandFragment.getInstance(classifyBean);
                    break;
            }
            LogUtils.i(TAG,"新建"+index);
            mMap.put(index,fragment);
        }
        return fragment;

    }


}
